package com.chinasofti.dao.impl;

import com.chinasofti.dao.UserDao;
import com.chinasofti.domain.User;
import com.chinasofti.util.JDBCUtils;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;

public class UserDaoImpl implements UserDao {
    @Override
    public void save(Connection connection,User user) {
        PreparedStatement pstm = null;
        try{
            pstm = connection.prepareStatement("INSERT INTO user VALUES(?,?,?,?,?,?,?,?)");
            pstm.setString(1,user.getUid());
            pstm.setString(2,user.getUcode());
            pstm.setString(3,user.getLoginname());
            pstm.setString(4,user.getPassword());
            pstm.setString(5,user.getUsername());
            pstm.setString(6,user.getGender());
            pstm.setDate(7,new Date(user.getBirthday().getTime()));
            pstm.setDate(8,new Date(user.getDutydate().getTime()));
            pstm.executeUpdate();
        }catch (Exception e){
            throw new RuntimeException(e);
        }finally{
            JDBCUtils.close(null,pstm,null);
        }

    }
}